package com.xnyzc.lhy.mis.controller.cmsapi.vehicle;

import com.xnyzc.lhy.common.entity.Rv;
import com.xnyzc.lhy.common.exception.PangException;
import com.xnyzc.lhy.common.penum.EErrorCode;
import com.xnyzc.lhy.common.util.CheckUtil;
import com.xnyzc.lhy.common.util.TokenUtil;
import com.xnyzc.lhy.mis.entity.param.cms.vehicle.CmsOaVehicleImport;
import com.xnyzc.lhy.mis.entity.param.cms.vehicle.CmsOaVehicleImportParam;
import com.xnyzc.lhy.mis.entity.vehicle.OaVehicleImportRecord;
import com.xnyzc.lhy.mis.service.cms.vehicle.ICmsVehicleImportService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description 车辆导入
 * @Author wangshuo
 * @Date 2019-12-04 15:48
 **/
@RestController
@RequestMapping(value = "cmsapi/vehicleImport")
public class CmsVehicleImportController {

    @Autowired
    private ICmsVehicleImportService iCmsVehicleImportService;

    /**
     * 导入
     * @param cmsOaCUserImportParam 入参
     * @return
     */
    @PostMapping(value = "vehicleImport")
    public Rv vehicleImport(@RequestBody CmsOaVehicleImportParam cmsOaCUserImportParam){
        long sysUserId = TokenUtil.getTokenUserId();
        String tag = TokenUtil.getTag();
        String clientId =TokenUtil.getClientId();
        if (CheckUtil.objIsEmpty(tag, clientId)){
            throw PangException.create(EErrorCode.missingAuthArgs);
        }
        List<CmsOaVehicleImport> cmsVehicleImportList = cmsOaCUserImportParam.getCmsOaVehicleImportList();
        if (CheckUtil.objIsEmpty(cmsVehicleImportList)){
            throw PangException.create(EErrorCode.missingArg);
        }
        return Rv.wrap(iCmsVehicleImportService.vehicleImport(sysUserId, tag, clientId, cmsVehicleImportList));
    }

    /**
     * 获取下载模板数据
     *
     * @return
     */
    @ApiOperation(value = "获取下载模板数据", notes = "获取下载模板数据")
    @GetMapping(value = "/getVehicleDownloadTemplate")
    public Rv getVehicleDownloadTemplate() {
        return iCmsVehicleImportService.getVehicleDownloadTemplate();
    }


    /**
     * 添加车辆导入记录
     * */
    @ApiOperation(value = "添加车辆导入记录", notes = "添加车辆导入记录")
    @PostMapping(value = "/addVehicleImportRecord")
    public Rv addVehicleImportRecord(@RequestBody OaVehicleImportRecord vehicleImportRecord){
        return iCmsVehicleImportService.addVehicleImportRecord(vehicleImportRecord);
    }

    /**
     * 车辆导入历史
     * @return
     */
    @ApiOperation(value = "车辆导入历史", notes = "车辆导入历史")
    @GetMapping(value = "/getQueryVehicleImportRecord")
    public Rv getQueryVehicleImportRecord(Integer size,Integer page){
        return iCmsVehicleImportService.getQueryVehicleImportRecord(size,page);
    }


}
